<?php
namespace TicTacToe\Dao;
use \TicTacToe\Model\Board;

class CookieBoardDao implements IBoardDao {
	
	private $cookieName;
	
	public function loadBoard() {
		$board = new Board();
		
		if(isset($_COOKIE[$this->cookieName]) && strlen($_COOKIE[$this->cookieName]) == 17) {
			$fields = explode(";", $_COOKIE[$this->cookieName]);
			$board->SetFields($fields);
		}
		
		return $board;
	}
	
	public function saveBoard($board) {
		setcookie($this->cookieName, implode(";", $board->GetFields()), 0);
	}
	
	public function setCookieName($cookieName) {
		$this->cookieName = $cookieName;
	}
}